<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="lib/vue.js"></script>
</head>
<body>
<div id="root">
    <button @click="ff">点我</button>
    <child :str="str"></child>
</div>
</body>
<script>
    new Vue({
        el : '#root',
        data :{
            str : 'sxx'
        },
        methods: {
            ff(){
                this.str+='!!!';
            }
        },
        components:{
            Child:{
                template:(`
                    <div>
                        <button @click="fn">{{num}}</button>
                        <p>{{str}}</p>
                    </div>

                `),
                data(){
                    return {
                        num :100
                    }
                },
                props:['str'],
                beforeUpdate(){
                    //视图更新之前
                    console.log('beforeUpdate',this.str,document.querySelector('p').innerText)
                },
                updated(){
                    console.log('updated',this.str,document.querySelector('p').innerText)
                },
                methods:{
                    fn(){
                        this.num++;
                    }
                }
            }
        }
    })
</script>
</html>